package org.ala.tiktools.generator.mybatis.creator.mapper;

import org.ala.tiktools.generator.mybatis.creator.entity.FieldInfo;
import org.ala.tiktools.generator.mybatis.creator.query.QueryFieldInfo;

import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @author ala
 * @date 2025-01-02 14:21
 */
public class MapperFieldInfo extends FieldInfo {


    /**
     *  是否参与查询
     */
    protected boolean query;
    protected String javaType;
    /**
     *  是否可模糊查
     */
    protected boolean like;
    /**
     *  是否可比较大小
     */
    protected boolean compare;

    public static MapperFieldInfo build(FieldInfo field) {
        MapperFieldInfo info = new MapperFieldInfo();
        //  type为空不参与查询
        if (field.getTypeClass() != null) {
            info.query = true;
        }
        //  字符串类型参与模糊查
        if (String.class.equals(field.getTypeClass())) {
            info.like = true;
        }
        //  数值类型参与比较查
        if (Integer.class.equals(field.getTypeClass())
                || Long.class.equals(field.getTypeClass())
                || BigDecimal.class.equals(field.getTypeClass())
                || Float.class.equals(field.getTypeClass())
                || Double.class.equals(field.getTypeClass())
                || Date.class.equals(field.getTypeClass())
                || Time.class.equals(field.getTypeClass())
                || Timestamp.class.equals(field.getTypeClass())
        ) {
            info.compare = true;
        }
        info.name = field.getName();
        info.columnName = field.getColumnName();
        info.set = field.getSet();
        info.get = field.getGet();
        info.desc = field.getDesc();
        info.type = field.getType();
        info.typeClass = field.getTypeClass();
        info.javaType = info.typeClass.getPackage().getName() + "." + info.typeClass.getSimpleName();
        info.onlyAutoIncrementPrimaryKey = field.isOnlyAutoIncrementPrimaryKey();
        return info;
    }

    public boolean isQuery() {
        return query;
    }

    public void setQuery(boolean query) {
        this.query = query;
    }

    public boolean isLike() {
        return like;
    }

    public void setLike(boolean like) {
        this.like = like;
    }

    public boolean isCompare() {
        return compare;
    }

    public void setCompare(boolean compare) {
        this.compare = compare;
    }

    public String getJavaType() {
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }
}
